<admintpl file="header" />
<style type="text/css">
    body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
</head>

<body>
<div style="padding: 20px;color:green;font-weight: bold;font-size: 20px;text-align: center">跑客数量：{$dispatch_count}人，听单中：<span id="count">-</span>人</div>
<div id="allmap">

</div>
<script type="text/javascript"
        src="https://api.map.baidu.com/api?v=2.0&ak=OkM4ci06ibVrimvizgsIWv0sjASIa7BK&s=1"></script>

<script type="text/javascript">
    var map = new BMap.Map("allmap");
    var point = new BMap.Point(113.65,34.76);
    map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
    map.enableContinuousZoom();
    map.centerAndZoom(point,14);

    var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角，添加比例尺
    var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
    var top_right_navigation = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}); //右上角

    map.addControl(top_left_control);
    map.addControl(top_left_navigation);
    map.addControl(top_right_navigation);
    //版权

    var cr = new BMap.CopyrightControl({anchor: BMAP_ANCHOR_TOP_RIGHT});   //设置版权控件位置
    map.addControl(cr); //添加版权控件

    var bs = map.getBounds();   //返回地图可视区域
    cr.addCopyright({id: 1, content: "<a href='#' style='font-size:14px;background:#000000;padding: 5px'>帮你跑腿大河跑客地图监控</a>", bounds: bs});

    function myFun(result){
        var cityName = result.name;
        map.setCenter(cityName);
        //alert("当前定位城市:"+cityName);
    }
    var myCity = new BMap.LocalCity();
    myCity.get(myFun);

    //=========================================
    pnRobRouteCounts();

    var myIcon1 = new BMap.Icon("__PUBLIC__/images/pn.png", new BMap.Size(30, 30));

    function pnRobRouteCounts() {
        $.ajax({
            type: "GET",
            async: true,
            url: "{:U('get_river_run_data')}",
            dataType: "json",
            success: function(data) {
                //console.log(data);
                $("#count").text(data.retValue.length);
                data = data.retValue;
                var pnpoint = new BMap.Point(data.longitude, data.latitude);

                map.clearOverlays();

                for (var i = 0; i < data.length; i ++) {
                    var point = new BMap.Point(data[i].longitude, data[i].latitude);

                    var content = data[i]['dispatch_name']+","+data[i]['mobile']+"</br>位置时间："+data[i]['place_up_time'];
                    var marker = new BMap.Marker(point, {icon: myIcon1});
                    marker.addEventListener("click",overlay_style);

                    map.addOverlay(marker);
                    var opts = {
                        position : point,    // 指定文本标注所在的地理位置
                        offset   : new BMap.Size(0, -35)    //设置文本偏移量
                    }
                    var label = new BMap.Label(content, opts);  // 创建文本标注对象
                    label.setStyle({
                        color : "red",
                        fontSize : "12px",
                        height : "auto",
                        lineHeight : "auto",
                        fontFamily:"微软雅黑"
                    });
                    map.addOverlay(label);


                }
            }
        });
        setTimeout("pnRobRouteCounts()",3000);
    }

    function overlay_style(e){
        var p = e.target;
        var pnpoint = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
        var geoc = new BMap.Geocoder();
        geoc.getLocation(pnpoint, function(rs){
            var addComp = rs.addressComponents;
            address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
            layer.alert(address);
        });


    }
</script>
</body>
</html>